//
//  MainTableViewCell.m
//  Funny
//
//  Created by dllo on 15/10/28.
//  Copyright © 2015年 King. All rights reserved.
//

#import "MainTableViewCell.h"

@implementation MainTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.scroll = [[UIScrollView alloc]init];
        [self.contentView addSubview:_scroll];
        self.scroll.userInteractionEnabled = NO;
        self.scroll.showsVerticalScrollIndicator = NO;
        self.scroll.contentSize = CGSizeMake(0, 675);
        
        self.iView = [[UIImageView alloc]init];
        [self.scroll addSubview:self.iView];
        
        self.countroy = [[UILabel alloc]init];
        self.countroy.textColor = [UIColor whiteColor];
        [self.contentView addSubview:self.countroy];
        self.countroy.textAlignment = NSTextAlignmentCenter;
        
        self.city = [[UILabel alloc]init];
        [self.contentView addSubview:self.city];
        self.city.textColor = [UIColor whiteColor];
        self.city.font = [UIFont systemFontOfSize:19.0];
        self.city.textAlignment = NSTextAlignmentCenter;
        
        self.cityE = [[UILabel alloc]init];
        [self.contentView addSubview:self.cityE];
        self.cityE.textColor = [UIColor whiteColor];
        self.cityE.textAlignment = NSTextAlignmentCenter;
        
        self.pic = [[UIImageView alloc]init];
        [self.contentView addSubview:self.pic];
        self.pic.image = [UIImage imageNamed:@"image.png"];
        
        self.foodImg = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"foods.png"]];
        [self.contentView addSubview:self.foodImg];
        
        self.shopImg = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"shop.png"]];
        [self.contentView addSubview:self.shopImg];
        
        self.playImg = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"play.png"]];
        [self.contentView addSubview:self.playImg];
        
        self.hotelImg = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"hotel.png"]];
        [self.contentView addSubview:self.hotelImg];
        
        self.foodNum = [[UILabel alloc]init];
        self.foodNum.textColor = [UIColor whiteColor];
        [self.contentView addSubview:self.foodNum];
        
        self.shopNum = [[UILabel alloc]init];
        self.shopNum.textColor = [UIColor whiteColor];
        [self.contentView addSubview:self.shopNum];
        
        self.playNum = [[UILabel alloc]init];
        self.playNum.textColor = [UIColor whiteColor];
        [self.contentView addSubview:self.playNum];
        
        self.hotelNUm = [[UILabel alloc]init];
        self.hotelNUm.textColor = [UIColor whiteColor];
        [self.contentView addSubview:self.hotelNUm];
    }
    return self;
}

#pragma mark - 使用Masonry适配

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    WeakSelf(weakSelf);
    [self.city mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.contentView).with.offset(20);
        make.centerX.equalTo(weakSelf.contentView);
        make.size.mas_equalTo(CGSizeMake(100, 40));
    }];
    
    [self.cityE mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.city.mas_bottom);
        make.centerX.equalTo(weakSelf.contentView);
        make.size.mas_equalTo(CGSizeMake(100, 30));
    }];
    
    [self.countroy mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.cityE.mas_bottom);
        make.centerX.equalTo(weakSelf.contentView);
        make.size.mas_equalTo(CGSizeMake(100, 30));
    }];
    
    [self.foodImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.contentView).with.offset(10);
        make.bottom.equalTo(weakSelf.contentView).with.offset(-10);
        make.size.mas_equalTo(CGSizeMake(20, 20));
    }];
    
    [self.foodNum mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.foodImg.mas_right).with.offset(5);
        make.bottom.equalTo(weakSelf.contentView).with.offset(-5);
        make.size.mas_equalTo(CGSizeMake(60, 30));
    }];
    
    [self.shopImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.contentView).with.offset(SelfWidth / 4 + 10);
        make.bottom.equalTo(weakSelf.contentView).with.offset(-10);
        make.size.mas_equalTo(CGSizeMake(20, 20));
    }];
    
    [self.shopNum mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.shopImg.mas_right).with.offset(5);
        make.bottom.equalTo(weakSelf.contentView).with.offset(-5);
        make.size.mas_equalTo(CGSizeMake(60, 30));
    }];
    
    [self.playImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.contentView).with.offset(SelfWidth / 2);
        make.bottom.equalTo(weakSelf.contentView).with.offset(-10);
        make.size.mas_equalTo(CGSizeMake(20, 20));
    }];
    
    [self.playNum mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.playImg.mas_right).offset(5);
        make.bottom.equalTo(weakSelf.contentView).with.offset(-5);
        make.size.mas_equalTo(CGSizeMake(60, 30));
    }];
    
    [self.hotelImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.contentView).with.offset(SelfWidth / 4 * 3);
        make.bottom.equalTo(weakSelf.contentView).with.offset(-10);
        make.size.mas_equalTo(CGSizeMake(20, 20));
    }];
    
    [self.hotelNUm mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.hotelImg.mas_right).offset(5);
        make.bottom.equalTo(weakSelf.contentView).with.offset(-5);
        make.size.mas_equalTo(CGSizeMake(60, 30));
    }];
    
    [self.pic mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.contentView);
        make.bottom.equalTo(weakSelf.contentView);
        make.size.mas_equalTo(CGSizeMake(SelfWidth, 45));
    }];
    self.scroll.frame = CGRectMake(0 , 0 , SelfWidth, SelfHeight - 1);
    self.iView.frame = CGRectMake(0, 0, SelfWidth, 675 * H);
}

// set方法 将model直接传到自定义cell赋值
- (void)setModel:(MainModel *)model
{
    self.city.text = model.name;
    self.cityE.text = model.alias;
    self.countroy.text = model.country;
    self.foodNum.text = model.cynum;
    self.shopNum.text = model.gwnum;
    self.playNum.text = model.jdnum;
    self.hotelNUm.text = model.hotelnum;
    [self.iView sd_setImageWithURL:[NSURL URLWithString:model.pic] placeholderImage:[UIImage imageNamed:@"earth.jpg"]];

}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
